import wx
import wx.grid

import stock.East as east

import threading
from view import dataframegrid as df_grid


class GenreView(wx.Panel):

    def __init__(self, parent=None):
        wx.Panel.__init__(self, parent=parent)
        # 根布局
        self.root_sizer = wx.BoxSizer(wx.VERTICAL)
        # 添加两个panel？

        # self.grid = grid
        self.grid = wx.grid.Grid(self)
        #
        self.root_sizer.Add(self.grid, 1, wx.EXPAND, 5)
        self.SetSizer(self.root_sizer)
        self.load_data()

    def load_data(self):
        t = threading.Thread(target=self._load_data)
        t.start()

    def _load_data(self):
        all_genes = east.all_genes()
        grid = self.grid
        # 建议是用这个类来
        try:
            grid.SetTable(df_grid.DataFrameGrid(all_genes))
            grid.AutoSize()
            grid.Refresh()
        except Exception as e:
            print(e)
        print('加载完成')


if __name__ == '__main__':
    app = wx.App(0)
    frame = wx.Frame(None)
    gv = GenreView(frame)
    frame.Show()
    app.MainLoop()
